home *** CD-ROM | disk | FTP | other *** search
/ SIGGRAPH 2002 Course Notes / SIGGRAPH 2002 - Course Notes - Disc 1.iso / pc / notes / 16 / supplemental-material / Pharr / sharpSpecular.sl < prev    next >
Encoding:
Text File  |  2002-04-05  |  639 b   |  22 lines

  1. /*
  2.  * sharpSpecular.sl
  3.  *
  4.  * Surface shader implementing sharp specular highlight model,
  5.  * stolen directly from the Advanced RenderMan book.
  6.  */
  7.  
  8. surface sharpSpecular(float Ka=1, Kd=1, Ks=1, sharpness = .1,
  9.                       roughness=.1; color specularcolor = 1) {
  10.     normal Nf = normalize(faceforward(N, I));
  11.     vector In = normalize(I);
  12.     float w = .18 * (1-sharpness);
  13.     illuminance(P, Nf, PI/2) {
  14.     vector Ln = normalize(L);
  15.     vector H = normalize(Ln + -In);
  16.     Ci += Cl * specularcolor * Ks *
  17.         smoothstep(.72-w, .72+w, pow(max(H . Nf, 0), 1/roughness));
  18.     }
  19.     Ci += Ka * ambient() + Kd * diffuse(Nf);
  20.     Ci *= Cs;
  21. }
  22.